(function ($) {
    Drupal.behaviors.aia_conversations = {
        attach: function(context, settings) {


            $(document).ready(function(){
//                aia_get_new_conversations();
            });


            function conversations_realtime_monitor() {
//                var conversations = aia_get_new_conversations();

//                setInterval(function() {
//
//
//
//                    if(messages != '') {
//                        $("#messages-top").after(messages).fadeIn();
//                    }
//
//
//                }, 2000);
            }

            function aia_get_new_conversations() {

                setInterval(function() {
                    $.getJSON("/account/messages/ajax/aia_get_new_conversations",function(result){
                        var counter = 0;
                        var html = '';
                        $.each(result, function(i, field){
                            counter++;
                            html += '<div>' + field.subject + '</div>';
                        });

                        if(counter > 0) {
                            $(".new_conversations").html(counter);
                            $(".new_conversations").removeClass('none');
//                            $('.new_conversations').tooltip({html: true, container:html})
//                            $('.new_conversations').popover(options)
                        }
                        else {
                            $(".new_conversations").html('');
                            $(".new_conversations").addClass('none');
                        }
                    });
                }, 2000);
            }

        }
    };
})(jQuery);